﻿using System.IO;
using System.Net;
using System.Web;
using System.Xml.Serialization;
using OAuthTools;
using TwitterWrapper.Resources;

namespace TwitterWrapper
{
    public class Twitter
    {
        private const string ConsumerKey = "yourConsumerKey";
        private const string ConsumerSecret = "yourConsumerSecret";
        private const string AccessToken = "yourAccessToken";
        private const string AccessTokenSecret = "yourAccessTokenSecret";

        public Status UpdateStatus(string status, WebProxy webProxy = null)
        {
            var query = string.Format("http://api.twitter.com/1/statuses/update.xml?status={0}", HttpUtility.UrlEncode(status));
            var request = new OAuth(ConsumerKey, ConsumerSecret, AccessToken, AccessTokenSecret);
            var result = request.PostResource(query);

            return Serialize(result);
        }

        public Status Serialize(string xml)
        {
            var xmlSerializer = new XmlSerializer(typeof(Status));
            var reader = new StringReader(xml);
            var status = (Status)xmlSerializer.Deserialize(reader);

            return status;
        }
    }
}
